home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000160_icon-group-sender _Mon Jul 19 08:29:31 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id IAA05286
for icon-group-addresses; Mon, 19 Jul 1999 08:29:23 -0700 (MST)
Message-Id: <199907191529.IAA05286@baskerville.CS.Arizona.EDU>
From: "Frank Lhota" <lhotaf@lexma.meitech.com>
To: <icon-group@optima.CS.Arizona.EDU>, "Garry" <memphis@macconnect.com>
Subject: Re: [Q][newbie] Why use a useless loop?
Date: Mon, 19 Jul 1999 11:22:52 -0400
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
You're right. the loop appears to be unnecessary. My guess is that it is a
fossil remain of a previous implementation.
One thing that strikes me about the implementation of both this procedure
and of basename is the use of a variable to store a position in the subject
string. Frankly, I do not know why this is done when a simpler and more
straightforward solution can be obtained by using the tab function. for
example, we can implement lastname as follows:
procedure lastname(s)
local line
line := trim(s)
line ?:= tab(find(",")) # Get rid of things like " ... , Jr."
line ? {
while tab(find(" ")+1) # Move past all blanks.
return tab(0)
}
end
Now isn't that clearer than the version that uses the local variable i to
store positions?
----- Original Message -----
From: Garry <memphis@macconnect.com>
To: <icon-group@optima.CS.Arizona.EDU>
Sent: Thursday, July 15, 1999 10:08 PM
Subject: [Q][newbie] Why use a useless loop?
> There is a wonderful little procedure, lastname(s), in the Icon Library
> for extracting the last name from a string s representing a person's
> full name. (It seems wonderful to me considering how compact yet
> tolerant it is, and how I would write it in other languages <ugh>).
>
> e.g. lastname("Dr. I. M. Zany, Jr.") produces a "Zany" result.
>
> The implementation is
> # File: lastname.icn
> # Subject: Procedure to produce last name
> # Author: Ralph E. Griswold
> # Date: April 30, 1993
> #
> # Produces the last name of a name in conventional form. Obviously, it
> # doesn't work for every possibility.
>
> procedure lastname(s)
> local line, i
>
> while line := trim(s) do {
> line ?:= tab(upto(',')) # Get rid of things like " ... , Jr."
> line ? {
> every i := upto(' ')
> tab(\i + 1)
> return tab(0)
> }
> }
> end
>
>
> My problem is that I can't think of any reason for writing
> while line := trim(s) do { ... }
> instead of just
> line := trim(s)
>
> Can anyone see a need for the "while"? If so, please teach me. I did of
> course already spend more than one full minute thinking about this and
> looked up trim() in the Icon book. Maybe there really is no need for the
> "while" but then I've observed that I'm blind to my blind spots.
>
> --
> Garry
> Tech Writer & Freelance Programmer
>